/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.haiberg.osgi.bundle.reportservice.activator;

import com.haiberg.osgi.bundle.reportservice.ReportFileHandler;
import com.haiberg.osgi.bundle.reportservice.ReportRequestHandler;
import com.haiberg.osgi.bundle.reportservice.factory.ReportFileHandlerFactory;
import com.haiberg.osgi.bundle.reportservice.factory.ReportRequestHandlerFactory;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

/**
 *
 * @author gyue
 */
public class Activator implements BundleActivator{

    private static BundleContext context = null;
    private ServiceRegistration<ReportFileHandler> reportFileHandlerRegistration;
    private ServiceRegistration<ReportRequestHandler> reportRequestHandlerRegistration;
    
    @Override
    public void start(BundleContext context) throws Exception {
        this.context = context;
        reportFileHandlerRegistration = context.registerService(ReportFileHandler.class, new ReportFileHandlerFactory(), null);
        reportRequestHandlerRegistration = context.registerService(ReportRequestHandler.class, new ReportRequestHandlerFactory(), null);
    }

    @Override
    public void stop(BundleContext context) throws Exception {
        reportFileHandlerRegistration.unregister();
        reportFileHandlerRegistration = null;
        reportRequestHandlerRegistration.unregister();
        reportRequestHandlerRegistration = null;
    }

    /**
     * @return the context
     */
    public static BundleContext getContext() {
        return context;
    }
}
